package cn.wh.controller;

import cn.wh.annotation.DataScope;
import cn.wh.dao.UserDao;
import cn.wh.entity.User;
import cn.wh.util.RedisUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
 * @Author wanghao
 * @Date 2022/5/1 17:11
 * @Description: TODO
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private HttpServletRequest request;

    @Resource
    private UserDao userDao;

    @GetMapping("/login")
    public String login(@RequestParam String userName, @RequestParam  String password) {
        String token = UUID.randomUUID().toString();
        User user = new User(1L,userName,password,"张三",false, Set.of(1,2));
        redisUtil.set(token,user);
        return "成功:" + token;
    }
    @DataScope(deptAlias = "tb_user",deptField = "id")
    @GetMapping("/page")
    public Page<User> page(){
        Page<User> page=new Page<>(1,10);
        Page<User> userPage = this.userDao.selectPage(page, null);
        return userPage;
    }


}
